﻿using Microsoft.Phone.Shell;
using System.Linq;

namespace Reuse.WP8.Extensions {
	/// <summary>
	/// Allows to do operations related to Tiles and the Shell using extension methods.
	/// </summary>
	public static class ShellHelper {
		/// <summary>
		/// Looks up a tile using it's Uri or part of it
		/// </summary>
		/// <param name="page">The object from which the method is called</param>
		/// <param name="partOfUri">The Uri portion to look up</param>
		/// <returns>The ShellTile found or null</returns>
		public static ShellTile FindTile( this object page, string partOfUri ) {
			ShellTile shellTile = ShellTile.ActiveTiles.FirstOrDefault(
				tile => tile.NavigationUri.ToString().Contains( partOfUri ) );

			return shellTile;
		}
	}
}
